#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e6+1000;
typedef long long LL;
typedef pair<LL,LL>P;
const LL mod=998244353;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
bool ma[maxn],vis[maxn];
int dx[2]={0,1};
int dy[2]={1,0};
LL st[maxn],sf[maxn];
LL n,m;
LL get(LL x,LL y){
   return (x-1)*m+y;
}
bool bfs(LL x,LL y){
    vis[get(x,y)]=1;
    queue<P>que;
    que.push({x,y});
    while(!que.empty()){
        P now=que.front();que.pop();
        LL x=now.first;LL y=now.second;
        for(int i=0;i<2;i++){
            LL nx=x+dx[i];LL ny=y+dy[i];
            if(nx<1||nx>n||ny<1||ny>m||vis[get(nx,ny)]||ma[get(nx,ny)]) continue;
            vis[get(nx,ny)]=1;
            que.push({nx,ny});
        }
    }
    if(vis[get(n,m)]) return true;
    else return false;
}
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   cin>>n>>m;
   for(LL i=1;i<=n;i++){
      for(LL j=1;j<=m;j++){
          char s;cin>>s;
          if(s=='#') ma[get(i,j)]=1;
      }
   }
   bool flag=bfs(1,1);
   if(!flag){cout<<"0"<<"\n";return 0;}
   st[get(1,1)]=1;
   for(LL i=1;i<=n;i++){
      for(LL j=1;j<=m;j++){
         if( ma[get(i,j)]==1) continue;
         if(i-1>=1) st[get(i,j)]=(st[get(i,j)]%mod+st[get(i-1,j)]%mod)%mod;
         if(j-1>=1) st[get(i,j)]=(st[get(i,j)]%mod+st[get(i,j-1)]%mod)%mod;
      }
   }
   sf[get(n,m)]=1;
   for(LL i=n;i>=1;i--){
      for(LL j=m;j>=1;j--){
        if(ma[get(i,j)]==1) continue;
        if(i+1<=n) sf[get(i,j)]=(sf[get(i,j)]%mod+sf[get(i+1,j)]%mod)%mod;
        if(j+1<=m) sf[get(i,j)]=(sf[get(i,j)]%mod+sf[get(i,j+1)]%mod)%mod;
      }
   }

   for(LL i=1;i<=n;i++){
      for(LL j=1;j<=m;j++){
        if ( (i==1&&j==1)||(i==n&&j==m) ) continue;
        if( st[get(i,j)]%mod*sf[get(i,j)]%mod==st[get(n,m)]%mod){
            cout<<"1"<<"\n";return 0;
        }
      }
   }
   cout<<"2"<<"\n";
   return 0;
}
